package com.tms.admin.controller;

import com.tms.admin.entity.TmsDriver;
import com.tms.admin.entity.vo.DriverQueryVO;
import com.tms.admin.service.TmsDriverService;
import com.tms.common.entity.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/*-----------------------------------
 *   @Time: 2022/9/6 20:06
 *   @Description: 司机管理
-----------------------------------*/
@Api(value = "司机管理")
@RestController
@RequestMapping("/driver")
@CrossOrigin
public class DriverController {
    @Autowired
    private TmsDriverService driverService;

    @ApiOperation(value = "根据查询条件分页/模糊查询司机信息")
    @PostMapping("page")
    public ResultVO getDriverPage(@RequestBody DriverQueryVO driverQueryVO){
        Map<String, Object> map = driverService.getPageByCondition(driverQueryVO);
        return ResultVO.ok().data("pageInfo", map);
    }

    @ApiOperation(value = "新增司机")
    @PostMapping
    public ResultVO addDriver(@RequestBody TmsDriver driver){
        driverService.addDriver(driver);
        return ResultVO.ok();
    }

    @ApiOperation(value = "删除司机")
    @DeleteMapping
    public ResultVO removeDriverById(@RequestBody List<Integer> driversIds){
        driverService.removeDriversById(driversIds);
        return ResultVO.ok();
    }

    @ApiOperation(value = "修改司机信息")
    @PutMapping
    public ResultVO modifyDriverById(@RequestBody TmsDriver driver){
        driverService.modifyDriverById(driver);
        return ResultVO.ok();
    }

    @ApiOperation(value = "查询所有的司机")
    @GetMapping
    public ResultVO getList(){
        List<TmsDriver> list = driverService.list();
        return ResultVO.ok().data("items", list);
    }
}
